
import 'package:flutter/material.dart';

void main() =>runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return MaterialApp(
        home:HYHomePage()
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return Scaffold(
      appBar: AppBar(
        title: Text("基础widget"),
      ),
      body:HYHomeContent(),
    );
  }
}

class HYHomeContent extends StatefulWidget {
  const HYHomeContent({super.key});

  @override
  State<HYHomeContent> createState() => _HYHomeContentState();
}
/**
 * 编辑器快捷键配置
 * preferences>keymap>找到冲突的快捷键extract，修改快捷键
 *alt+z抽取成一个widget
 *
 */
class _HYHomeContentState extends State<HYHomeContent> {
  final imageURL ="https://t7.baidu.com/it/u=2638406194,523661981&fm=193&f=GIF";
  final ButtonStyle style =
      ElevatedButton.styleFrom(
        textStyle: const TextStyle(
          fontSize: 20
        )
      );
  @override
  Widget build(BuildContext context) {
   // return ButtonExtensionDemo(style: style);

    //return imageExtentionDemo(imageURL: imageURL);

    return IconExtentionDemo();
  }
}

class IconExtentionDemo extends StatelessWidget {

  /*
    * Icon字体图标和图片图标
    * 1、字体图标矢量图（放大的时候不会失真）
    * 2、字体图标可以设置颜色
    * 3、图标很多时，占据空间更小
    * */
  const IconExtentionDemo({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Icon(Icons.pets,size:300);
  }
}

class imageExtentionDemo extends StatelessWidget {
  const imageExtentionDemo({
    super.key,
    required this.imageURL,
  });

  final String imageURL;
//1.占位图的问题
  @override
  Widget build(BuildContext context) {
    return FadeInImage(
        fadeOutDuration: Duration(milliseconds:2000),
        placeholder:AssetImage("assets/images/pic.png"),
        image:NetworkImage(imageURL)
    );
  }
}

class ButtonExtensionDemo extends StatelessWidget {
  const ButtonExtensionDemo({
    super.key,
    required this.style,
  });

  final ButtonStyle style;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children:<Widget> [
          ElevatedButton(
              style:style,
              onPressed: null,
              child: const Text('Enabled')
          )
        ],
      ),
    );
  }
}

class ImageDemo02 extends StatelessWidget {
  const ImageDemo02({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Image(
      //1、在Flutter项目中创建一个文件夹，存储图片
      //2、在pubspec.yaml进行配置
      //使用图片
        image: AssetImage("assets/images/pic.png")
    );
  }
}

class ImageDemo01 extends StatelessWidget {
  const ImageDemo01({
    super.key,
    required this.imageURL,
  });

  final String imageURL;

  @override
  Widget build(BuildContext context) {
    return Image(
      image: NetworkImage(imageURL),
      width: 200,
      height: 200,
      fit:BoxFit.fitWidth,
      alignment: Alignment(0,-2),
      color: Colors.red,
    );
  }
}
